package com.rd.student.wulian.wanggaobo.day0728.practice02;

import java.util.Arrays;

public class MaxGap {
    public static int getMaxGap(int[] nums) {
        if (nums == null || nums.length < 2) {
            return 0;
        }
        Arrays.sort(nums); // 将数组排序

        int maxGap = 0;
        for (int i = 1; i < nums.length; i++) {
            int gap = nums[i] - nums[i - 1];
            if (gap > maxGap) {
                maxGap = gap;
            }
        }

        return maxGap;
    }

    public static void main(String[] args) {
        int[] nums = {9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5};
        int maxGap = getMaxGap(nums);
        System.out.println(maxGap);
    }
}